package p270jp.pxv.android.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.view.View;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceGroupAdapter;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import p014ae.C0063d5;
import p041ba.C1048a;
import p090d0.C2518n;
import p134ei.PixivAnalytics;
import p134ei.PremiumAnalyticsSource;
import p210hh.PixivAccountManager;
import p270jp.pxv.android.R;
import p270jp.pxv.android.activity.AccountSettingActivity;
import p270jp.pxv.android.activity.OptoutSettingsActivity;
import p270jp.pxv.android.activity.PointActivity;
import p270jp.pxv.android.activity.PremiumActivity;
import p270jp.pxv.android.activity.ProfileEditActivity;
import p270jp.pxv.android.activity.WorkspaceEditActivity;
import p270jp.pxv.android.commonObjects.model.ApplicationConfig;
import p270jp.pxv.android.fragment.SettingFragment;
import p325m0.MutabilityOwnership;
import p347mm.AccountUtils;
import p355n3.PreferenceInflater;
import p370ni.AccountEditActivityMode;
import p381o3.C5429d;
import p436q6.C5768b;
import p468re.LogoutService;
import p491sd.C6034a;
import p547uh.C6578v3;
import p547uh.Hilt_SettingFragment;
import p603wm.AbstractC6949c;
import p625xi.LegacyNavigation;
import p625xi.SettingNavigation;
import p639y6.C7291g;
import p639y6.C7292h;
import p639y6.C7301s;
import p645yc.AndroidSchedulers;
import p665z6.C7460o;
import p665z6.C7461p;
import p671zc.CompositeDisposable;

/* renamed from: jp.pxv.android.fragment.a */
/* loaded from: classes2.dex */
public class SettingFragment extends Hilt_SettingFragment {

    /* renamed from: t */
    public static final /* synthetic */ int f19042t;

    /* renamed from: n */
    public CompositeDisposable f19043n;

    /* renamed from: o */
    public AbstractC6949c<PixivAnalytics> f19044o;

    /* renamed from: p */
    public AbstractC6949c<LogoutService> f19045p;

    /* renamed from: q */
    public SettingNavigation f19046q;

    /* renamed from: r */
    public AbstractC6949c<LegacyNavigation> f19047r;

    /* renamed from: s */
    public ApplicationConfig f19048s;

    /* JADX WARN: Finally extract failed */
    @Override // androidx.preference.PreferenceFragmentCompat
    /* renamed from: c */
    public void mo4612c(Bundle bundle, String str) {
        boolean z;
        PreferenceManager eVar = this.f3403b;
        if (eVar != null) {
            Context context = getContext();
            PreferenceScreen preferenceScreen = this.f3403b.f3434g;
            eVar.f3432e = true;
            PreferenceInflater eVar2 = new PreferenceInflater(context, eVar);
            XmlResourceParser xml = context.getResources().getXml(R.xml.preferences);
            try {
                Preference c = eVar2.m3485c(xml, preferenceScreen);
                xml.close();
                PreferenceScreen preferenceScreen2 = (PreferenceScreen) c;
                preferenceScreen2.m11012p(eVar);
                SharedPreferences.Editor editor = eVar.f3431d;
                if (editor != null) {
                    editor.apply();
                }
                eVar.f3432e = false;
                PreferenceManager eVar3 = this.f3403b;
                PreferenceScreen preferenceScreen3 = eVar3.f3434g;
                if (preferenceScreen2 != preferenceScreen3) {
                    if (preferenceScreen3 != null) {
                        preferenceScreen3.mo10998s();
                    }
                    eVar3.f3434g = preferenceScreen2;
                    z = true;
                } else {
                    z = false;
                }
                if (z) {
                    this.f3405d = true;
                    if (this.f3406e && !this.f3408g.hasMessages(1)) {
                        this.f3408g.obtainMessage(1).sendToTarget();
                    }
                }
                Context context2 = getContext();
                int i = AccountSettingActivity.f18290A;
                AccountEditActivityMode aVar = AccountEditActivityMode.Edit;
                Intent intent = new Intent(context2, AccountSettingActivity.class);
                intent.putExtra("EDIT_MODE", aVar);
                Preference b = mo10980b(getString(R.string.preference_key_setting_account));
                if (b != null) {
                    b.f3328e = new Preference.AbstractC0749c(intent, 109) { // from class: uh.u9

                        /* renamed from: b */
                        public final /* synthetic */ Intent f28067b;

                        /* renamed from: c */
                        public final /* synthetic */ int f28068c;

                        {
                            this.f28067b = r2;
                            this.f28068c = r3;
                        }

                        @Override // androidx.preference.Preference.AbstractC0749c
                        /* renamed from: c */
                        public final boolean mo133c(Preference preference) {
                            SettingFragment aVar2 = SettingFragment.this;
                            Intent intent2 = this.f28067b;
                            int i2 = this.f28068c;
                            int i3 = SettingFragment.f19042t;
                            aVar2.startActivityForResult(intent2, i2);
                            return false;
                        }
                    };
                }
                Context context3 = getContext();
                int i2 = ProfileEditActivity.f18539a0;
                m4610h(R.string.preference_key_setting_profile, new Intent(context3, ProfileEditActivity.class));
                Context context4 = getContext();
                MutabilityOwnership.m3745m(context4, "context");
                m4610h(R.string.preference_key_setting_workspace, new Intent(context4, WorkspaceEditActivity.class));
                Context context5 = getContext();
                MutabilityOwnership.m3745m(context5, "context");
                m4610h(R.string.preference_key_setting_optout, new Intent(context5, OptoutSettingsActivity.class));
                m4610h(R.string.preference_key_setting_register_premium, PremiumActivity.m4769V0(requireContext(), PremiumAnalyticsSource.SETTING));
                C7461p pVar = new C7461p(this, 27);
                Preference b2 = mo10980b(getString(R.string.preference_key_notification_notify));
                if (b2 != null) {
                    b2.f3328e = pVar;
                }
                C5768b bVar = new C5768b(this, 25);
                Preference b3 = mo10980b(getString(R.string.preference_key_app_theme_setting));
                if (b3 != null) {
                    b3.f3328e = bVar;
                }
                Context context6 = getContext();
                MutabilityOwnership.m3745m(context6, "context");
                m4610h(R.string.preference_key_setting_point, new Intent(context6, PointActivity.class));
                String string = getString(R.string.zendesk_help_url);
                Preference b4 = mo10980b(getString(R.string.preference_key_support_help));
                if (b4 != null) {
                    b4.f3328e = new C7460o(this, string, 5);
                }
                m4609i(R.string.preference_key_support_terms, "https://policies.pixiv.net/?appname=pixiv_android");
                m4609i(R.string.preference_key_support_privacy_policy, "https://policies.pixiv.net/?appname=pixiv_android#privacy");
                m4609i(R.string.preference_key_support_law, "https://policies.pixiv.net/?appname=pixiv_android#notation");
                m4609i(R.string.preference_key_act_on_settlement, "https://policies.pixiv.net/?appname=pixiv_android#shikin");
                m4609i(R.string.preference_key_support_guideline, "https://www.pixiv.net/terms/?page=guideline&appname=pixiv_ios");
                mo10980b(getString(R.string.preference_key_support_copyright)).f3328e = new C1048a(this, 19);
                Preference b5 = mo10980b(getString(R.string.preference_key_setting_logout));
                if (PixivAccountManager.m5511e().f16506l) {
                    b5.f3328e = new C7292h(this, 22);
                } else if (b5.f3345v) {
                    b5.f3345v = false;
                    Preference.AbstractC0748b bVar2 = b5.f3317F;
                    if (bVar2 != null) {
                        PreferenceGroupAdapter cVar = (PreferenceGroupAdapter) bVar2;
                        cVar.f3420h.removeCallbacks(cVar.f3421i);
                        cVar.f3420h.post(cVar.f3421i);
                    }
                }
                mo10980b(getString(R.string.preference_key_app_version)).mo11024B(this.f19048s.getVersionName());
                if (!PixivAccountManager.m5511e().f16506l) {
                    PreferenceCategory preferenceCategory = (PreferenceCategory) mo10980b("setting");
                    preferenceCategory.m11004I(mo10980b(getString(R.string.preference_key_setting_account)));
                    preferenceCategory.m11004I(mo10980b(getString(R.string.preference_key_setting_profile)));
                    preferenceCategory.m11004I(mo10980b(getString(R.string.preference_key_setting_logout)));
                }
                if (PixivAccountManager.m5511e().f16503i) {
                    PreferenceCategory preferenceCategory2 = (PreferenceCategory) mo10980b("setting");
                    preferenceCategory2.m11004I(mo10980b(getString(R.string.preference_key_setting_register_premium)));
                    preferenceCategory2.m11004I(mo10980b(getString(R.string.preference_key_setting_optout)));
                }
            } catch (Throwable th) {
                xml.close();
                throw th;
            }
        } else {
            throw new RuntimeException("This should be called after super.onCreate.");
        }
    }

    /* renamed from: g */
    public final void m4611g() {
        this.f19043n.mo82c(this.f19045p.getValue().m2585a().m1008i(C6034a.f26178c).m1011f(AndroidSchedulers.m334a()).m1010g(new C6578v3(this, 1), C0063d5.f316c));
    }

    /* renamed from: h */
    public final void m4610h(int i, Intent intent) {
        Preference b = mo10980b(getString(i));
        if (b != null) {
            b.f3328e = new C7291g(this, intent, 10);
        }
    }

    /* renamed from: i */
    public final void m4609i(int i, String str) {
        Preference b = mo10980b(getString(i));
        if (b != null) {
            b.f3328e = new C5429d(this, str, 7);
        }
    }

    @Override // androidx.fragment.app.Fragment
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i == 109 && i2 == -1 && intent.getBooleanExtra("result_key_should_show_mail_authorization", false)) {
            AccountUtils.m3550d(getContext(), this.f19043n);
        }
    }

    @Override // androidx.preference.PreferenceFragmentCompat, androidx.fragment.app.Fragment
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.f19043n = new CompositeDisposable();
        this.f19044o = C2518n.m7638h(PixivAnalytics.class);
        this.f19045p = C2518n.m7638h(LogoutService.class);
        this.f19047r = C2518n.m7638h(LegacyNavigation.class);
    }

    @Override // androidx.fragment.app.Fragment
    public void onDestroy() {
        this.f19043n.m80f();
        super.onDestroy();
    }

    @Override // androidx.preference.PreferenceFragmentCompat, androidx.fragment.app.Fragment
    public void onViewCreated(View view, Bundle bundle) {
        super.onViewCreated(view, bundle);
        getChildFragmentManager().m11251d0("logout_dialog_fragment_result_key", getViewLifecycleOwner(), new C7301s(this, 23));
    }
}
